﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace HodhodNews.Extraction
{
    public class ArtilceNode
    {
        public ArtilceNode()
        {
            this.ChildArtilceNodes = new List<ArtilceNode>();
            this.Language = Language.Arabic;
            this.ConfidenceLevel = 1;
        }

        /// <summary>
        /// Gets or sets value indecates the level of confidence that this node contains the article
        /// </summary>
        public int ConfidenceLevel { get; set; }
        public string NodeName { get; set; }
        public int CharactersLength { get; set; }
        public int Links { get; set; }
        public int Images { get; set; }
        public bool Ignore { get; set; }
        public HtmlNode HtmlNode { get; set; }
        public HtmlNode ArticleTopParent { get; set; }
        public Language Language { get; set; }
        public int OrderIndex { get; set; }

        public List<ArtilceNode> ChildArtilceNodes
        {
            get;
            set;
        }

        public override string ToString()
        {
            string parentString = null;

            if (this.ArticleTopParent != null && this.ArticleTopParent.Attributes["id"] != null)
            {
                parentString = " ,ParentID=" + this.ArticleTopParent.Attributes["id"].Value;
            }
            else if (this.ArticleTopParent != null && this.ArticleTopParent.Attributes["class"] != null)
            {
                parentString = " ,ParentClass=" + this.ArticleTopParent.Attributes["class"].Value;
            }

            string parentName = this.ArticleTopParent == null ? "NO_PARENT" : this.ArticleTopParent.Name;
            string parentId = this.ArticleTopParent == null ? "" : this.ArticleTopParent.OId.ToString();

            return string.Format("ParentName={0}, Confidence Level={1}, NodeName={2}, CharactersLength={3}, ParentID={4}",
                string.Format("{0}", parentName + parentString),
                this.ConfidenceLevel,
                this.NodeName,
                this.CharactersLength,
                parentId
                );
        }
    }
}
